package com.itheima.hashmapdemo1;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class HashMapDemo1 {
    public static void main(String[] args) {
        HashMap<Student, String> hm = new HashMap<>();

        Student s1 = new Student("xiaohei", 23);
        Student s2 = new Student("dapang", 22);
        Student s3 = new Student("xiaomei", 22);

        hm.put(s1, "江苏");
        hm.put(s2, "北京");
        hm.put(s3, "天津");

        // 遍历方式1
        Set<Student> keys = hm.keySet();
        for (Student key : keys) {
            String value = hm.get(key);
            System.out.println(key + "---" + value);
        }

        System.out.println("---------------------------");

        // 遍历方式2
        Set<Map.Entry<Student, String>> entries = hm.entrySet();
        for (Map.Entry<Student, String> entry : entries) {
            Student key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key + "---" + value);
        }

        System.out.println("---------------------------");

        // 遍历方式3
        hm.forEach((key, value) -> System.out.println(key + "---" + value));
    }
}
